package com.course.business.controller.admin;

import com.course.business.controller.BaseController;
import com.course.model.dto.CourseContentFileDto;
import com.course.model.dto.PageDto;
import com.course.common.response.BaseResponse;
import com.course.model.util.ValidatorUtil;
import com.course.model.service.CourseContentFileService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/course-content-file")
public class CourseContentFileController extends BaseController{

    public static final String BUSINESS_NAME = "课程内容文件";

    @Resource
    private CourseContentFileService courseContentFileService;

    /**
     * 列表查询
     */
    @GetMapping("/getCourseContentFileList/{courseId}")
    public BaseResponse list(@PathVariable String courseId) {
        BaseResponse response = new BaseResponse().sucess();
        response.setData(courseContentFileService.list(courseId));
        return response;
    }

    /**
     * 保存，id有值时更新，无值时新增
     */
    @PostMapping("/save")
    public BaseResponse save(@RequestBody CourseContentFileDto courseContentFileDto) {
        // 保存校验
        ValidatorUtil.require(courseContentFileDto.getCourseId(), "课程id");
        ValidatorUtil.length(courseContentFileDto.getUrl(), "地址", 1, 100);
        ValidatorUtil.length(courseContentFileDto.getName(), "文件名", 1, 100);

        BaseResponse response = new BaseResponse().sucess();
        courseContentFileService.save(courseContentFileDto);
        response.setData(courseContentFileDto);
        return response;
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public BaseResponse delete(@PathVariable String id) {
        BaseResponse response = new BaseResponse().sucess();
        courseContentFileService.delete(id);
        return response;
    }
}
